#include <stdio.h>
#include <stdlib.h>

#define Max(a,b) ((a)>(b)?(a):(b))
int maxFreeTime(int eventTime, int k, int* startTime, int startTimeSize, int* endTime, int endTimeSize) {
    int *times=malloc(sizeof(int)*(startTimeSize+1));
    times[0]=startTime[0];
    times[startTimeSize]=eventTime-endTime[startTimeSize-1];
    for( int i=1; i < startTimeSize; i++ )
        times[i]=startTime[i]-endTime[i-1];
    int max,sum=0;
    for( int i=0; i < startTimeSize + 1; i++ ){
        sum+=times[i];
        // k+1
        if( i < k )
            continue;
        max=Max(max,sum);
        sum-=times[ i - k ];
    }
    return max;
}

int main(){
    int e=5,k=2;
    int st[]={0,1,2,3,4};
    int et[]={1,2,3,4,5};
    printf("%d\n",maxFreeTime(e,k,st,sizeof(st)/sizeof(int),
        et,sizeof(et)/sizeof(int)));
    return 0;
}
